--POUR CONTROLE



define erp='erp_mli2.';
define outils='outils_mli2.';

--CREATE TABLE se_par_port AS (SELECT * FROM &erp.par_port WHERE 1=2);


DELETE FROM se_par_port;


 INSERT INTO se_par_port
 (SELECT id  port_cod,
         NULL destana_cod,
         NULL postana_cod,
         Nvl(famcpta,'POR') fam_cod,
         0 enreg_id,
         codtpf tpfart_cod,
         Decode(codtva,3,0,codtva) tvaart_cod,
         Nvl(devise,'EUR') devise_cod,
         'N' basepied_cod,
         'N' enreg_s,
         libelle port_lib,
         NULL port_lib2,
         'T' tiers_typ,
         'N' portrlq_ok,
         'A' calcliv_typ

    FROM uv_ccode_port) ;

 UPDATE se_par_port tf SET enreg_id=(select enreg_id FROM &erp.par_port f WHERE f.port_cod=tf.port_cod) ;
 UPDATE se_par_port tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('port_cod','PAR_PORT','O') ;

 commit;


select * from (
SELECT &outils.stragg(source) source,port_cod, destana_cod, postana_cod, fam_cod, enreg_id, tpfart_cod, tvaart_cod, devise_cod, basepied_cod, enreg_s, port_lib, port_lib2, tiers_typ, portrlq_ok, calcliv_typ
FROM (
  SELECT 'uv' source ,g.* FROM se_par_port g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.par_port g
  )
GROUP BY port_cod, destana_cod, postana_cod, fam_cod, enreg_id, tpfart_cod, tvaart_cod, devise_cod, basepied_cod, enreg_s, port_lib, port_lib2, tiers_typ, portrlq_ok, calcliv_typ
HAVING Count(1)!=2) r
ORDER BY port_cod;